package com.xlh.enums.course;

import com.google.common.collect.Lists;
import com.xlh.enums.ResourcesTypeEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Objects;

/**
 * 章节资源展示时的枚举
 * <p>
 * Created by lx on 2019/1/28.
 */
@Getter
@NoArgsConstructor
@AllArgsConstructor
public enum ChapterResourceViewEnum {

    THEORY(1, "理论学习",
            Lists.newArrayList(ResourcesTypeEnum.COURSEWARE, ResourcesTypeEnum.THEORY_VIDEO)) {
        @Override
        public String getName(CodeEnum codeEnum) {
            return codeEnum == null || codeEnum == CodeEnum.BACHELOR_DEGREE ? getMessage() : "任务引导";
        }
    },
    PREPARATION_MATERIALS(2, "备课材料",
            Lists.newArrayList(ResourcesTypeEnum.PREPARATION_MATERIALS, ResourcesTypeEnum.THEORY_VIDEO)),
    RESOURCE(3, "教学资源",
            Lists.newArrayList(ResourcesTypeEnum.LEARNING_RESOURCES, ResourcesTypeEnum.OTHER_RESOURCES)),
    PRACTICE(4, "随堂练习",
            Lists.newArrayList(ResourcesTypeEnum.PRACTICE)),
    EXPERIMENT(5, "实验学习",
            Lists.newArrayList(ResourcesTypeEnum.LABORATORY_MANUAL,
                    ResourcesTypeEnum.EXPERIMENT_VIDEO, ResourcesTypeEnum.LABORATORY_TARGET)) {
        @Override
        public String getName(CodeEnum codeEnum) {
            return codeEnum == null || codeEnum != CodeEnum.MANY_EXPERIMENT ? getMessage() : "任务%s %s";
        }
    };

    private Integer code;

    private String message;

    private List<ResourcesTypeEnum> resourcesTypeEnums;

    public String getName(CodeEnum codeEnum) {
        return message;
    }

    public static ChapterResourceViewEnum getByCode(Integer code) {
        if (code == null) return null;
        for (ChapterResourceViewEnum chapterResourceViewEnum : ChapterResourceViewEnum.values()) {
            if (Objects.equals(chapterResourceViewEnum.getCode(), code)) {
                return chapterResourceViewEnum;
            }
        }
        return null;
    }

    public static String getMessageByCode(Integer code) {
        ChapterResourceViewEnum chapterResourceViewEnum = getByCode(code);
        return chapterResourceViewEnum == null ? null : chapterResourceViewEnum.getMessage();
    }

}
